<template>
  <div class="activity-list-item">
    <div class="activity-cover">
      <img :src="activity.cover" :alt="activity.title" />
    </div>
    <div class="activity-info">
      <div class="activity-title">{{ activity.title }}</div>
      <div class="activity-description">{{ truncateDescription(activity.description) }}</div>
      <div class="activity-meta">
        <div class="activity-location">
          <van-icon name="location-o" />
          <span>{{ activity.location }}</span>
        </div>
        <div class="activity-time">
          <van-icon name="clock-o" />
          <span>{{ formatTime(activity.startTime) }}</span>
        </div>
      </div>
      <div class="activity-tags">
        <van-tag 
          v-for="(tag, index) in activity.tags" 
          :key="index"
          type="primary"
          color="#4080ff"
          plain
          size="small"
          class="tag"
        >
          {{ tag }}
        </van-tag>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue';
import dayjs from 'dayjs';

const props = defineProps({
  activity: {
    type: Object,
    required: true
  }
});

// 截断描述文本
const truncateDescription = (text) => {
  if (!text) return '';
  return text.length > 60 ? text.substring(0, 60) + '...' : text;
};

// 格式化时间
const formatTime = (time) => {
  if (!time) return '时间待定';
  return dayjs(time).format('YYYY-MM-DD HH:mm');
};
</script>

<style lang="scss" scoped>
.activity-list-item {
  display: flex;
  background-color: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  transition: transform 0.2s, box-shadow 0.2s;
  
  &:active {
    transform: scale(0.98);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.03);
  }
  
  .activity-cover {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
    
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  
  .activity-info {
    flex: 1;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    
    .activity-title {
      font-size: 16px;
      font-weight: 500;
      color: #333;
      margin-bottom: 6px;
      line-height: 1.3;
    }
    
    .activity-description {
      font-size: 13px;
      color: #666;
      margin-bottom: 8px;
      line-height: 1.4;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    
    .activity-meta {
      display: flex;
      font-size: 12px;
      color: #999;
      margin-bottom: 8px;
      
      .activity-location, .activity-time {
        display: flex;
        align-items: center;
        margin-right: 12px;
        
        .van-icon {
          font-size: 14px;
          margin-right: 4px;
          color: #4080ff;
        }
      }
    }
    
    .activity-tags {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      
      .tag {
        font-size: 10px;
        padding: 0 6px;
        border-radius: 10px;
        background-color: rgba(64, 128, 255, 0.08);
        border-color: rgba(64, 128, 255, 0.2);
      }
    }
  }
}
</style>